
package com.phm.phmneuron.connection;

import com.phm.phmneuron.neuron.Neuron;
import java.util.Objects;

/**
 *
 * @author PARHAM
 */
public class Connection implements Cloneable {
    public Neuron neuronOne = null;
    public Neuron neuronTwo = null;
    public float edgeValue = 0;
    
    public Connection () {
        // Empty body
    }
    public Connection (Neuron one, Neuron two) {
        neuronOne = one;
        neuronTwo = two;
    }
    public Connection (Neuron one, Neuron two, float edge) {
        this (one, two);
        edgeValue = edge;
    }
    
    public boolean include (Neuron neuron) {
        return (neuron != null &&
               (neuron.equals(neuronOne) ||
                neuron.equals(neuronTwo)));
    }
    public Neuron connectTo (Neuron neuron) {
        if (neuron == null) return null;
        if (neuron.equals(neuronOne)) return neuronTwo;
        if (neuron.equals(neuronTwo)) return neuronOne;
        return null;
    }
    
    @Override
    public String toString () {
        return "Neuron edge : " + edgeValue;
    }
    @Override
    public boolean equals (Object obj) {
        if (obj != null && 
            obj instanceof Connection) {
            final Connection con = (Connection) obj;
            return (con.neuronOne.equals(neuronOne) || con.neuronOne.equals(neuronTwo)) &&
                   (con.neuronTwo.equals(neuronOne) || con.neuronTwo.equals(neuronTwo));
        }
        return false;
    }
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 89 * hash + Objects.hashCode(this.neuronOne);
        hash = 89 * hash + Objects.hashCode(this.neuronTwo);
        return hash;
    }
    @Override
    public Object clone () {
        return new Connection(neuronOne, neuronTwo, edgeValue);
    }
}
